// fillings for result header
#include "Includes.hpp" // includes for project
#include "Result.hpp" // class declarations

Result::Result() {
    cout << "\n\tyou are doing it wrong! see result class";
}

Result::Result(istream* in) {
    (*in).ignore(2, '\n'); // ignore newline
    (*in) >> date; (*in).ignore(2, '#'); 
    (*in) >> homegoals; (*in).ignore(2, '#');
    (*in) >> awaygoals; // read 'date', 'homegoals', 
    (*in).ignore(2, '#');
    (*in) >> normalplaytime; // 'awaygoals', 'normalplaytime' 
    (*in).ignore(2, '#'); // and ignore delimiters in between
    for (int hsvar = 0; hsvar <= homegoals; hsvar++) {
	(*in) >> homescorers[hsvar]; // read homescorers
	(*in).ignore(2, '#'); // ignore delimiter
    }
    for (int asvar = 0; asvar <= awaygoals; asvar++) {
	(*in) >> awayscorers[asvar]; // read awayscorers
	(*in).ignore(2, '#'); // ignore delimiter
    }
}

void Result::writeToFile(ofstream* out) {
    (*out) << date << " #" << homegoals << " #" // write date, goals
	   << awaygoals << " #" << normalplaytime; // and normalplaytime
    for (int hsvar = 0; hsvar <= homegoals; hsvar++) {
	(*out) << homescorers[hsvar] << " #"; // write homescorers
    }
    for (int asvar = 0; asvar <= awaygoals; asvar++) {
	(*out) << awayscorers[asvar] << " #"; // write awayscorers
    }
}

void Result::makeTable(Table* hometeam, Table* awayteam, int type) {
	int woncount, lostcount = 0, tiedcount = 1;
	if(type == 1 || (type == 3 && normalplaytime)) {
		woncount = 2;
	} else {
		woncount = 3;
	}
	if(homegoals != -1) { // calculating points
		if(homegoals > awaygoals) {
			hometeam->won++; awayteam->lost++;
			hometeam->points += woncount;
			awayteam->points += lostcount;
		} else if (homegoals < awaygoals) {
			hometeam->lost++; awayteam->won++;
			hometeam->points += lostcount;
			awayteam->points += woncount;
		} else {
			hometeam->tied++; awayteam->tied++;
			hometeam->points += tiedcount;
			awayteam->points += tiedcount;
		}
	}
}
